package com.konsung.ksdc.common.widget;

import android.view.View;

/**
 * 防止点击事件多次响应，限制响应时间间隔至少为1秒
 * Created by DJH on 2017/4/5 0005.
 */
public abstract class OnMultiClickListener implements View.OnClickListener {

    private static final int MIN_CLICK_DELAY_TIME = 1000; // 两次点击按钮之间的点击间隔不能少于1000毫秒

    private static long lastClickTime; // 记录上次点击时间戳

    /**
     * 构造方法
     * @param v view
     */
    public abstract void onMultiClick(View v);

    @Override
    public void onClick(View v) {
        long curClickTime = System.currentTimeMillis();
        if ((curClickTime - lastClickTime) >= MIN_CLICK_DELAY_TIME) {
            // 超过点击间隔后再将lastClickTime重置为当前点击时间
            lastClickTime = curClickTime;
            onMultiClick(v);
        }
    }
}
